import { Inject, Injectable } from '@nestjs/common';
import { HttpLog } from './schemas/http.schema';
import { Model } from 'mongoose';
import { IHttpLog } from './logger.types';
import config from 'src/config';

@Injectable()
export class LoggerService {
	constructor(
		@Inject('HTTP_LOG_MODEL')
		private readonly httpLogModel: Model<HttpLog>,
	){}

	async writeHttpLog(params:IHttpLog):Promise<string>{
		let nodeEnv=process.env.NODE_ENV||"local"
		let isServer=nodeEnv=="docker"
		// if(!isServer)return
		if(isNaN(params.timeMs)){
			params.timeMs=0
		}
		let log=new this.httpLogModel(params)
		await log.save()
		return log._id
	}
}
